<%@ include file="/WEB-INF/jsp/include/taglib.jsp" %>

<h1>
    <a href="<c:url value="/forum.form"/>"><fmt:message key="app.forum.topic.list"/></a>
    :
    <a href="<c:url value="/topic.form/${entry.parent.id}"/>"><c:out value="${entry.parent.header}"/></a>
</h1>


<div class="entry">
    <div class="entry-left">
        <img src="/static-images/pic-post.gif">
    </div>
    <div class="entry-right">
        <div class="entry-header">
            <c:out value="${entry.header}"/>
        </div>
        <div class="entry-data">
            <fmt:message key="app.forum.author"/>:
            <a href="<c:url value="/viewprofile.form/${entry.author.username}"/>"><b>${entry.author.username}</b></a>
            <fmt:message key="app.forum.date"/>: <b>
            <fmt:formatDate type="both" value="${entry.date}"/>
        </b>
            <fmt:message key="app.forum.post.commentscount"/>: <b><c:out value="${entry.commentCount}"/></b>

            <authz:authorize ifAllGranted="ROLE_SUPERVISOR">
            <a href="<c:url value="/system/editpost.form/${entry.id}"/>"><b><fmt:message key="app.system.edit"/></a></b>
        </authz:authorize>
    </div>
    <div class="entry-text">
        ${entry.text}
    </div>
</div>
</div>
<br/><br/>

<c:set var="skip" value="${param['skip']}"/>
<c:set var="portion" value="${__applicationConfig.defaultPortion}"/>
<c:set var="total" value="${entry.commentCount}"/>


<c:if test="${total > portion}">
    <div style="text-align: left;">
        <a href="<c:url value="/post.form/${entry.id}">
    <c:param name="skip" value="0"/>
</c:url>">&lt;&lt; <fmt:message key="app.forum.comments.firstpage"/></a>
        :
        <a href="<c:url value="/post.form/${entry.id}">
    <c:param name="skip" value="${skip - portion > 0 ? skip - portion : 0}"/>
</c:url>">&lt; <fmt:message key="app.forum.comments.prevpage"/></a>
        ::
        <a href="<c:url value="/post.form/${entry.id}">
    <c:param name="skip" value="${(skip + portion) > (total - portion) ? (total-portion) : (skip + portion)}"/>
</c:url>"><fmt:message key="app.forum.comments.nextpage"/>&gt;</a>
        :
        <a href="<c:url value="/post.form/${entry.id}">
    <c:param name="skip" value="${total - portion}"/>
</c:url>"><fmt:message key="app.forum.comments.lastpage"/>&gt;&gt;</a>
    </div>
    <br/>
</c:if>

<c:forEach items="${comments}" var="comment">
    <c:choose>
        <c:when test="${comment.author.blocked}">
            <div class="entry">
                <div class="comment-left">
                    <div class="entry-comment-header">
                        <s>
                            <fmt:message key="app.forum.date"/>: <b>
                            <fmt:formatDate  type="both" value="${comment.date}"/>
                        </b>
                            <fmt:message key="app.forum.author"/>: <b>${comment.author.username}</b>
                        </s>
                    </div>
                    <div class="entry-text">
                        <i><fmt:message key="app.forum.replyofblockeduser"/></i>
                    </div>
                </div>
            </div>
        </c:when>
        <c:when test="${comment.parent.author.blocked}">
            <div class="entry">
                <div class="comment-left">
                    <div class="entry-comment-header">
                        <fmt:message key="app.forum.date"/>: <b>
                        <fmt:formatDate type="both" value="${comment.date}"/>
                    </b>
                        <fmt:message key="app.forum.author"/>:
                        <a href="<c:url value="/viewprofile.form/${comment.author.username}"/>"><b>${comment.author.username}</b></a>
                    </div>
                    <div class="entry-text">
                        <i><fmt:message key="app.forum.replytoblockeduser"/></i>
                    </div>
                </div>
            </div>
        </c:when>
        <c:otherwise>
            <div class="entry">
                <div class="comment-left">
                    <div class="entry-comment-header">
                        <fmt:message key="app.forum.date"/>: <b>
                        <fmt:formatDate type="both" value="${comment.date}"/>
                    </b>
                        <fmt:message key="app.forum.author"/>:
                        <a href="<c:url value="/viewprofile.form/${comment.author.username}"/>"><b>${comment.author.username}</b></a>
                    </div>
                    <div class="entry-text">
                        <c:out value="${entry:previewComment(comment.text)}" escapeXml="false"/>
                        <c:if test="${entry:isShortenedComment(comment.text)}">
                            <a href="<c:url value="/replycomment.form/${comment.id}"/>"><fmt:message
                                    key="app.entry.readEntire"/></a>
                        </c:if>
                    </div>
                    <div class="entry-comment-footer">
                        <c:if test="${!entry.commentsBlocked}">
                            <a href="<c:url value="/replycomment.form/${comment.id}"/>">
                                <fmt:message key="app.forum.comment.reply"/>
                            </a>
                        </c:if>
                    </div>
                </div>
            </div>
        </c:otherwise>
    </c:choose>
</c:forEach>


<c:choose>
    <c:when test="${!entry.commentsBlocked}">
        <a href="<c:url value="/addcomment.form/${entry.id}"/>">
            <fmt:message key="app.forum.comment.add"/>
        </a>
    </c:when>
    <c:otherwise>
        <i>(<fmt:message key="app.forum.post.commentsblocked"/>)</i>
    </c:otherwise>
</c:choose>

<c:if test="${total > portion}">
    <br/>

    <div style="text-align: left;">
        <a href="<c:url value="/post.form/${entry.id}">
    <c:param name="skip" value="0"/>
</c:url>">&lt;&lt; <fmt:message key="app.forum.comments.firstpage"/></a>
        :
        <a href="<c:url value="/post.form/${entry.id}">
    <c:param name="skip" value="${skip - portion > 0 ? skip - portion : 0}"/>
</c:url>">&lt; <fmt:message key="app.forum.comments.prevpage"/></a>
        ::
        <a href="<c:url value="/post.form/${entry.id}">
    <c:param name="skip" value="${(skip + portion) > (total - portion) ? (total-portion) : (skip + portion)}"/>
</c:url>"><fmt:message key="app.forum.comments.nextpage"/>&gt;</a>
        :
        <a href="<c:url value="/post.form/${entry.id}">
    <c:param name="skip" value="${total - portion}"/>
</c:url>"><fmt:message key="app.forum.comments.lastpage"/>&gt;&gt;</a>
    </div>
</c:if>